<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="会议名称" prop="meetingName">
        <el-input
          v-model="queryParams.meetingName"
          placeholder="请输入会议名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="会议室地点" prop="meetingRoomId">
        <!-- <el-input
          v-model="queryParams.meetingRoomId"
          placeholder="请输入会议室地点"
          clearable
          @keyup.enter.native="handleQuery"
        /> -->
        <el-select v-model="queryParams.meetingRoomId"  placeholder="请选择会议室地点"  clearable   @keyup.enter.native="handleQuery" >
                <el-option
                  v-for="item in meetingRoomIdList"
                  :key="item.roomId"
                  :label="item.roomName"
                  :value="item.roomId"
                ></el-option>
              </el-select>
      </el-form-item>

      <el-form-item label="会议状态" prop="staus">
        <!-- <el-input
          v-model="queryParams.staus"
          placeholder="请输入会议状态"
          clearable
          @keyup.enter.native="handleQuery"
        /> <template slot-scope="scope"> -->
         <!-- <dict-tag :options="dict.type.eamp_meeting" :value="scope.row.staus">

         </dict-tag> -->
         <el-select v-model="queryParams.staus" :disabled="isreadonly"  placeholder="请选择会议状态">
                <el-option
                  v-for="dict in dict.type.eamp_meeting"
                  :key="dict.value"
                  :label="dict.label"
                  :value="dict.value"
                ></el-option>
              </el-select>



      </el-form-item>
      <!-- <el-form-item label="删除" prop="delFlg">
        <el-input
          v-model="queryParams.delFlg"
          placeholder="请输入删除(0删除 1正常)"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item> -->

      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['eamp:meeting:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['eamp:meeting:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['eamp:meeting:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['eamp:meeting:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="meetingList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="会议id" align="center" prop="meetingId" />
      <el-table-column label="会议名称" align="center" prop="meetingName" />
      <el-table-column label="会议室地点" align="center" prop="eampMeetingRoom.roomName" />
      <el-table-column label="部门" align="center" prop="sysDept.deptName" />
      <el-table-column label="创建人" align="center" prop="sysUser.userName" />
      <el-table-column label="会议状态" align="center" prop="staus" >
      <template slot-scope="scope">
         <dict-tag :options="dict.type.eamp_meeting" :value="scope.row.staus">

         </dict-tag>
        </template>
      </el-table-column>
      <el-table-column label="紧急程度" align="center" prop="urgency" >
        <template slot-scope="scope">
         <dict-tag :options="dict.type.sys_jinjizhuangtai" :value="scope.row.urgency">

         </dict-tag>
        </template>
      </el-table-column>
      <!-- <el-table-column label="会议类型" align="center" prop="meetingType" /> -->
      <el-table-column label="开始时间" align="center" prop="startDate" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.startDate, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>

      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['eamp:meeting:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['eamp:meeting:remove']"
          >删除</el-button>

          <el-button
            size="mini"
            type="text"
            icon="el-icon-view"
            @click="handlese(scope.row)"
            v-hasPermi="['eamp:meeting:list']"
          >查看</el-button>

          <el-button
            size="mini"
            type="text"
            icon="el-icon-view"
            @click="handleUpdate1(scope.row)"
            v-hasPermi="['eamp:meeting:edit']"
          >新增会议纪要</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
    <el-dialog :title="title" :visible.sync="open1" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px" :disabled="isreadonly">
      <el-form-item label="附件" prop="attachments" :disabled="isreadonly">
        <!-- <el-input v-model="form.attachments" :readonly="isreadonly"  type="textarea" placeholder="请输入内容" /> -->
        <file-upload  v-model="form.attachments" />
        <!-- <uploadFile :uploadParams="传递参数" @getFileIdReturn="接受上传文件id数组回传"></uploadFile>   -->
      </el-form-item>

      </el-form>
      <div slot="footer" class="dialog-footer">
      <el-button type="primary" @click="submitForm">确 定</el-button>
      <el-button @click="cancel">取 消</el-button>
    </div>
    </el-dialog>
    <!-- 添加或修改会议记录对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px" :disabled="isreadonly">
        <el-form-item label="会议名称" prop="meetingName">
          <el-input v-model="form.meetingName"  :disabled="isreadonly"  placeholder="请输入会议名称" />
        </el-form-item>
        <el-form-item label="会议室地点" prop="meetingRoomId">
          <!-- <el-input v-model="form.meetingRoomId" placeholder="请输入会议室地点" /> -->
          <el-select v-model="form.meetingRoomId" :disabled="isreadonly"  placeholder="请选择会议室地点">
                <el-option
                  v-for="item in meetingRoomIdList"
                  :key="item.roomId"
                  :label="item.roomName"
                  :value="item.roomId"
                ></el-option>
              </el-select>


            </el-form-item>
        <el-form-item label="部门" prop="deptId">
          <!-- <el-input v-model="form.deptId" placeholder="请输入部门" /> -->
          <treeselect :disabled="isreadonly"  v-model="form.deptId" :options="deptOptions" :show-count="true" placeholder="请选择部门" />
          <!-- <el-select v-model="form.deptId"   placeholder="请输入部门">
                <el-option
                  v-for="item in deptIdList"
                  :key="item.deptId"
                  :label="item.deptName"
                  :value="item.deptId"

                ></el-option>
              </el-select> -->
        </el-form-item>
        <el-form-item label="联系人" prop="contectpeople">
          <!-- <el-input v-model="form.creatBy" placeholder="请输入创建人" /> -->
          <el-select v-model="form.contectpeople"   placeholder="请选择联系人" @change="selectConnect" :disabled="isreadonly" >
                <el-option
                  v-for="item in attendeesList"
                  :key="item.userId"
                  :label="item.userName"
                  :value="item.userId"
                ></el-option>
              </el-select>
        </el-form-item>
        <!-- <el-form-item label="会议状态" prop="staus">
          <el-input v-model="form.staus" placeholder="请输入会议状态" />
        </el-form-item> -->

        <el-form-item label="联系方式" prop="delFlg">
          <el-input v-model="form.phone" placeholder="请输入联系方式"   :disabled="isreadonly"  />
        </el-form-item>
        <el-form-item label="紧急程度" prop="urgency">
          <!-- <el-input v-model="form.urgency" placeholder="请输入紧急程度" /> -->
          <el-select v-model="form.urgency" :disabled="isreadonly"  placeholder="请选择紧急程度">
                <el-option
                  v-for="dict in dict.type.sys_jinjizhuangtai"
                  :key="dict.value"
                  :label="dict.label"
                  :value="dict.value"
                ></el-option>
              </el-select>
        </el-form-item>
        <el-form-item label="会议类型" prop="meetingType">
          <el-select v-model="form.meetingType" :disabled="isreadonly"  placeholder="请选择会议类型">
            <el-option
              v-for="dict in dict.type.sys_huiyileixing"
              :key="dict.value"
              :label="dict.label"
              :value="dict.value"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="开始时间" prop="startDate" v-if="a===true">
          <el-input v-model="form.startDate"  :disabled="isreadonly"  />
        </el-form-item>
        <el-form-item :disabled="isreadonly"   label="开始时间至结束时间" prop="startDate" v-else-if="a===false">
          <!-- <el-date-picker clearable
            v-model="form.startDate"
            type="datetime"
            value-format="yyyy-MM-dd HH:mm:ss"
            placeholder="请选择开始时间"
            align="right"
            :picker-options="pickerOptions">
          </el-date-picker> -->
          <el-date-picker
      v-model="form.startAndEnd"
      type="datetimerange"
      value-format="yyyy-MM-dd HH:mm:ss"
      range-separator="至"
      start-placeholder="开始日期"
      end-placeholder="结束日期">

    </el-date-picker>

        </el-form-item>



        <!-- <el-form-item label="结束时间" prop="endDate">
          <el-date-picker clearable
            v-model="form.endDate"
            type="datetime"
            value-format="yyyy-MM-dd HH:mm:ss:"
            placeholder="请选择结束时间"
            align="right"
            :picker-options="pickerOptions">
          </el-date-picker>
        </el-form-item> -->
        <el-form-item label="密码" prop="meetingPassword">
          <el-input v-model="form.meetingPassword" :disabled="isreadonly"   placeholder="请输入密码" />
        </el-form-item>
        <el-form-item label="附件" prop="attachments" :disabled="isreadonly">
          <!-- <el-input v-model="form.attachments" :readonly="isreadonly"  type="textarea" placeholder="请输入内容" /> -->
          <file-upload  v-model="form.attachments" />
           <!-- <uploadFile :uploadParams="传递参数" @getFileIdReturn="接受上传文件id数组回传"></uploadFile>   -->
        </el-form-item>
        <el-form-item label="内容" :disabled="isreadonly">
          <editor v-model="form.content" :disabled="isreadonly" :min-height="192"/>
        </el-form-item>
        <el-form-item label="备注" prop="remark">
          <el-input v-model="form.remark" type="textarea" :disabled="isreadonly"   placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="主持人" prop="compere">
          <!-- <el-input v-model="form.compere" placeholder="请输入主持人" /> -->
          <el-select v-model="form.compere" :disabled="isreadonly"  placeholder="请选择主持人">
                <el-option
                  v-for="item in compereList"
                  :key="item.userId"
                  :label="item.userName"
                  :value="item.userId"

                ></el-option>
              </el-select>
        </el-form-item>
        <el-form-item label="分享人" prop="sharer">
          <!-- <el-input v-model="form.sharer" placeholder="请输入分享人" /> -->
          <el-select v-model="form.sharer" :disabled="isreadonly"   multiple  placeholder="请选择分享人">
                <el-option
                  v-for="item in sharerList"
                  :key="item.userId"
                  :label="item.userName"
                  :value="item.userId"

                ></el-option>
              </el-select>
        </el-form-item>
        <el-form-item label="与会人" prop="attendees">
          <!-- <el-input v-model="form.attendees" placeholder="请输入与会人" /> -->
          <el-select v-model="form.attendees"  :disabled="isreadonly"  multiple  placeholder="请选择与会人">
                <el-option
                  v-for="item in attendeesList"
                  :key="item.userId"
                  :label="item.userName"
                  :value="item.userId"

                ></el-option>
              </el-select>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listMeeting, getMeeting, delMeeting, addMeeting, updateMeeting } from "@/api/eamp/meeting";
import {listUser,deptTreeSelect} from "@/api/system/user";
import { listDeptList } from "@/api/system/dept";
import { listMeetingroomid } from "@/api/eamp/meeting_room";
import Treeselect from "@riophae/vue-treeselect";
import "@riophae/vue-treeselect/dist/vue-treeselect.css";
export default {
  name: "Meeting",
  dicts:['sys_jinjizhuangtai','sys_huiyileixing','eamp_meeting'],
  components: { Treeselect },
  data() {
    return {
      isreadonly: false,
      pickerOptions: {
          shortcuts: [{
            text: '今天',
            onClick(picker) {
              picker.$emit('pick', new Date());
            }
          }]
        },
        // startDate: '',
        startDate: [new Date(2000, 10, 10, 10, 10), new Date(2000, 10, 11, 10, 10)],
        // datetime: '',

      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
        // 部门树选项
      deptOptions: undefined,
            // 部门名称
      deptName: undefined,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      a:true,
      // 会议记录表格数据
      meetingList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      open1: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        meetingName: null,
        meetingRoomId: null,
        deptId: null,
        creatBy: null,
        staus: null,
        delFlg: null,
        urgency: null,
        meetingType: null,
        startDate: null,
        endDate: null,
        meetingPassword: null,
        attachments: null,
        content: null,
        compere: null,
        sharer: null,
        attendees: null
      },
      // 表单参数
      form: {},
      defaultProps: {
        children: "children",
        label: "label"
      },
      // 表单校验
      rules: {
      },
      //定义一个主持人列表
      compereList:[],
      //定义一个分享人列表
      sharerList:[],
      //定义一个与会人列表
      attendeesList:[],
       //定义一个与会人列表
      creatByrList:[],
      //会议室id
      meetingRoomIdList:[],
      //部门
      deptIdList:[],

    };
  },
  watch: {
    // 根据名称筛选部门树
    deptName(val) {
      this.$refs.tree.filter(val);
    }
  },
  created() {
    this.getList();
    this.getDeptTree();
    this.getUser();


  },
  methods: {
    //选中联系人后触发
    selectConnect(value){
      console.log(value)
      this.attendeesList.forEach(eve=>{
        console.log(eve);
        if(eve.userId===value){
          this.form.phone=eve.phonenumber
        }
      })
    },
    /** 查询会议记录列表 */
    getList() {
      this.loading = true;
      listMeeting(this.queryParams).then(response => {
        this.meetingList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
     /** 查询部门下拉树结构 */
     getDeptTree() {
      deptTreeSelect().then(response => {
        this.deptOptions = response.data;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.open1 = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.isreadonly =false,
      this.form = {
        meetingId: null,
        meetingName: null,
        meetingRoomId: null,
        deptId: null,
        creatBy: null,
        createTime: null,
        staus: null,
        delFlg: null,
        urgency: null,
        meetingType: null,
        startDate: null,
        endDate: null,
        meetingPassword: null,
        attachments: null,
        content: null,
        remark: null,
        compere: null,
        sharer: null,
        attendees: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.meetingId)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },

    getUser(){
      listUser().then(res=>{
        if (res.code===200){
       this.sharerList=res.rows
       this.compereList=res.rows
       this.attendeesList=res.rows

        }
      })
    },
    /** 新增按钮操作 */
    handleAdd() {
this.a=false;
      this.reset();
      this.open = true;
      this.title = "添加会议记录";



      listMeetingroomid().then(res=>{
        if (res.code===200){
       this.meetingRoomIdList=res.rows
        }
      })

      listDeptList().then(res=>{
        if (res.code===200){
       this.deptIdList=res.rows
        }
      })



    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const meetingId = row.meetingId || this.ids
      getMeeting(meetingId).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改会议记录";

      });
    },/** 修改按钮操作 */
    handleUpdate1(row) {
      this.reset();
      const meetingId = row.meetingId || this.ids
      getMeeting(meetingId).then(response => {
        this.form = response.data;
        this.open1 = true;
        this.title = "新增会议纪要";

      });
    },
    /** =查看按钮 */
    handlese(row) {
      this.a=true;
      this.reset();
      const meetingId = row.meetingId || this.ids
      getMeeting(meetingId).then(response => {
        this.form = response.data;
        this.isreadonly=true;
        this.open = true;
        this.title = "查看会议管理";

      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.meetingId != null &&this.title==="修改会议记录") {
            updateMeeting(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else if (this.form.meetingId != null &&this.title==="查看会议管理") {
            updateMeeting(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.isreadonly = false;
              this.getList();
            });
          }

          else {
            addMeeting(this.form).then(response => {
              console.log(this.form);

              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
            // console.log(this.form.startDate);

          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const meetingIds = row.meetingId || this.ids;
      this.$modal.confirm('是否确认删除会议记录编号为"' + meetingIds + '"的数据项？').then(function() {
        return delMeeting(meetingIds);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('eamp/meeting/export', {
        ...this.queryParams
      }, `meeting_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
